import { defineStore } from 'pinia';
import { ref } from 'vue';

interface Breadcrumb {
  title: string;
  path: string;
}

export const useCommonStore = defineStore('common', () => {
  // 状态
  const loading = ref<boolean>(false);
  const sidebarCollapsed = ref<boolean>(false);
  const breadcrumbs = ref<Breadcrumb[]>([]);

  // 方法
  const setLoading = (loadingState: boolean) => {
    loading.value = loadingState;
  };

  const toggleSidebar = () => {
    sidebarCollapsed.value = !sidebarCollapsed.value;
  };

  const setSidebarCollapsed = (collapsed: boolean) => {
    sidebarCollapsed.value = collapsed;
  };

  const setBreadcrumbs = (breadcrumbList: Breadcrumb[]) => {
    breadcrumbs.value = breadcrumbList;
  };

  return {
    // 状态
    loading,
    sidebarCollapsed,
    breadcrumbs,
    // 方法
    setLoading,
    toggleSidebar,
    setSidebarCollapsed,
    setBreadcrumbs,
  };
});
